/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import java.io.*;
import org.apache.commons.fileupload.FileItemStream;

/**
 *
 * @author HDKhanh
 */
public class UploadFile {
    public static boolean processfile(String path, FileItemStream item){
        try{
            File f = new File(path + File.separator + "skin/images/sp");
            if(!f.exists()) f.mkdir();
            File savedFile = new File(f.getAbsolutePath()+File.separator+item.getName());
            FileOutputStream fos = new FileOutputStream(savedFile);
            InputStream is = item.openStream();
            int x = 0;
            byte[] b = new byte[1024];
            while((x = is.read(b)) != -1){
                fos.write(b,0,x);
            }
            fos.flush();
            fos.close();
            return true;
        } catch (Exception e){
            e.printStackTrace();
        }
        return false;
    }
}
